package com.example.tms.dto;

import com.example.tms.entity.Employee;
import com.example.tms.entity.EmployeeDepartment;
import lombok.Data;

@Data
public class EmployeeDetailDTO extends Employee {
    // 部门关联信息
    private Integer depId;          // 部门ID
    private String position;       // 职位
    
    // 显式添加getter方法确保可用性
    public Integer getDepId() {
        return depId;
    }
    
    public String getPosition() {
        return position;
    }
    private Integer superiorId;    // 上级ID
    private Integer creatorId;     // 创建者ID
    private Integer approverId;    // 审批者ID
    private String state = "已通过"; // 状态
    private String depDescription;  // 部门描述
    private Integer isCurrent = 1; // 是否当前部门

    public EmployeeDetailDTO() {}

    public EmployeeDetailDTO(Employee employee, EmployeeDepartment departmentInfo) {
        // 复制员工基本信息
        this.setId(employee.getId());
        this.setName(employee.getName());
        this.setPassword(employee.getPassword());
        this.setGender(employee.getGender());
        this.setPhone(employee.getPhone());
        this.setBirthDate(employee.getBirthDate());
        this.setHireDate(employee.getHireDate());
        this.setEducation(employee.getEducation());
        this.setStatus(employee.getStatus());
        this.setEmpType(employee.getEmpType());
        this.setEmpPhoto(employee.getEmpPhoto());
        this.setSchool(employee.getSchool());
        this.setDescription(employee.getDescription());
        this.setIsDeleted(employee.getIsDeleted());
        this.setCreatedAt(employee.getCreatedAt());
        this.setUpdatedAt(employee.getUpdatedAt());
        
        // 设置部门相关信息
        if (departmentInfo != null) {
            this.depId = departmentInfo.getDepId();
            this.position = departmentInfo.getPosition();
            this.superiorId = departmentInfo.getSuperiorId();
            this.creatorId = departmentInfo.getCreatorId();
            this.approverId = departmentInfo.getApproverId();
            this.state = departmentInfo.getState();
            this.depDescription = departmentInfo.getDescription();
            this.isCurrent = departmentInfo.getIsCurrent();
        }
    }

    public EmployeeDepartment toEmployeeDepartment() {
        EmployeeDepartment ed = new EmployeeDepartment();
        ed.setDepId(this.depId);
        ed.setPosition(this.position);
        ed.setSuperiorId(this.superiorId);
        ed.setCreatorId(this.creatorId);
        ed.setApproverId(this.approverId);
        ed.setState(this.state);
        ed.setDescription(this.depDescription);
        ed.setIsCurrent(this.isCurrent);
        return ed;
    }
}
